/**
 * ipc渲染器
 */
const ipcRenderer = window.ipcRenderer
/**
 * @param {Request} request 请求类
 * @returns Response
 */
export default async function (request) {
  const response = new Response()
  const jsonData = await ipcRenderer.invoke(request.url, JSON.stringify(request.data))
  response.data = JSON.parse(jsonData)
  return response
}

/**
 * 请求类
 * @param method 方法
 * @param baseURL 基础url
 * @param url url
 * @param data  请求数据
 * @param header  请求头
 * @constructor
 */
export class Request {
  constructor(method, baseURL, url, data, header) {
    this.method = method
    this.baseURL = baseURL
    this.url = url
    this.data = data
    this.header = header
  }
}

/**
 * 响应类
 */
export class Response {
  constructor(result, error) {
    this.result = result
    this.error = error
  }
}
